package _97DieDaiQi.impl;

import _97DieDaiQi.Container;
import _97DieDaiQi.Iterator;

/**
 * @NameRepository: Container接口 实现类
 * @author: ZBoHang
 * @time: 2021/9/17 14:18
 */
public class NameRepository implements Container {
    private String[] names;

    public NameRepository(String[] names) {
        this.names = names;
    }

    @Override
    public Iterator getIterator() {
        return new NameIterator();
    }

    private class NameIterator implements Iterator {
        int index;
        @Override
        public boolean hasNext() {
            return index < names.length;
        }

        @Override
        public Object next() {
            return this.hasNext()?names[index++]:null;
        }
    }
}
